// module 模块  


// model  模型   数据模型  

// {id:Number,name:String,age:Number} 


// Schema  结构 
// Schema主要用于定义MongoDB中集合Collection里文档document的结构
// 表结构的定义(不仅仅可以定义文档的结构和属性，还可以定义文档的实例方法、静态模型方法、复合索引等)


// 定义Schema非常简单，指定字段名和类型即可，支持的类型包括以下8种

// String      字符串
// Number      数字    
// Date        日期
// Buffer      二进制
// Boolean     布尔值
// Mixed       混合类型
// ObjectId    对象ID    
// Array       数组

var mongoose = require("mongoose")
// var Schema = mongoose.Schema;    // 解构
var { Schema, model } = mongoose;

var user_schema = new Schema({
    username: String,
    usernames: String,
    password: String,
    age: Number,
    word: String,
    address: String,
    time: Date,
    phone: String,
    confirm_Password: String,
    avatar: String,
})


// Model是由Schema编译而成的假想（fancy）构造器，具有抽象属性和行为
// Model的每一个实例（instance）就是一个document，document可以保存到数据库和对数据库进行操作
// model是由schema生成的模型，可以对数据库的操作

// model(集合名称,Schema)


// 英语复数 
// users = users
// city =  cities 
// ooh =  oohes 

// mine1 = mine1 
exports.UserModel = model("user1", user_schema) // 集合名称  bug 


var movie_schema = new Schema({
    "genres": Array,
    "casts": Array,
    "directors": Array,
    "rating": Object,
    "title": String,
    "time": Date,
    "collect_count": Number,
    "original_title": String,
    "subtype": String,
    "year": String,
    "images": Object,
    "alt": String,
    "id": String,
    "text": String,
    "username": String,
})

exports.MvModel = model('movies', movie_schema)


var conment_schema = new Schema({
    username: String,
    time: Date,
    img: String,
    text: String,
    cid: String,
    movie: Object
})

exports.conModel = model('conment1', conment_schema)


var Fmshoucang_schema = new Schema({
    username: String,
    time: Date,
    img: String,
    text: String,
    id: String,
    movie: Object,
    albumid: String,
    type: Boolean,

})

exports.Fmshoucang = model('Fmshoucangs', Fmshoucang_schema)

var pinglun_schema = new Schema({
    username: String,
    time: Date,
    img: String,
    text: String,
    id: String,
    albumid: String,
    pl: String,
})

exports.pinglun = model('pingluns', pinglun_schema)


/***超管后台Scmal***/

var adminUser_schema = new Schema({
    "username": String,
    "password": String,
    "phone": String,
    "avatar": String,
    "role": String,  // 0 普通用户  1 管理员  2 超级管理员 
    "age": Number,
    "sex": String,
    "money": Number,
    "alone": String,
})

exports.AdminUser = model('adminuser1', adminUser_schema)

var tiWen_schema = new Schema({
    "username": String,
    "phone": String,
    "time": Date,
    "tiwen": Number,
    isTest: Boolean,
})

exports.tiWen = model('tiwen1', tiWen_schema)


var gao_schema = new Schema({
    "title": String,
    content: String,
    img: String,
    time: Date,
    author: String
})

exports.GongGao = model('gonggao1', gao_schema)

var keyword_schema = new Schema({
    "username": String,
    price: Number,
    time: Date,
    isuse: Number,
    key: String,
    usetime: Date,

})

exports.keyword = model('keyword1', keyword_schema)


var fanli_schema = new Schema({
    "username": String,
    alone: String,
    fanmoney: Number,
    time: Date,
    money: Number,
    modl: Number,
})

exports.fanli = model('fanli1', fanli_schema)

var tousu_schema = new Schema({
    "username": String,
    time: Date,
    answer: Number,
    title: String,
    content: String,
})

exports.tousu = model('tousu1', tousu_schema)


var huifu_schema = new Schema({
    "username": String,
    time: Date,
    shoujianren: String,
    title: String,
    content: String,
    answerid: String,
})

exports.huifu = model('huifu1', huifu_schema)